<template>
	<view class="AddressList">
		<view v-if="!loading && list.length">
			<view class="address por margin-bottom-16 f-background radius12"
				v-for="(item,index) in list" :key="index">
				<view class="address-item font-weight-600 color3 size-30" @click="onOptionsType(item.id,item)">
					<view class="name">{{item.communityName || '-'}}</view>
					<view class="margin-bottom-12">
						<text v-if="item.building">{{item.building}}栋</text>
						<text v-if="item.unit">{{item.unit}}单元</text>
						<text v-if="item.number">{{item.number}}号</text>
						<text v-if="item.addressInfo">{{item.addressInfo}}</text>
					</view>
					<view class="color-9e font-weight-400 size-26">{{item.consignee}}{{sexData[item.sex]}}
						{{item.telephone}}
					</view>
				</view>
				<!-- <image class="add-icon poa" src="@/static/icons/bj.png" mode="" @click="onJumpPage('address',item.id)">
				</image> -->
			</view>
		</view>
		<view v-if="!loading && !list.length">
			<Default tisName="暂无可用地址数据!" />
		</view>
		<view class="delivery dis font-weight-400 size-28" v-if="noList.length">
			以下地址不在配送范围内
		</view>
		<view v-if="!loading && noList.length">
			<view class="address por margin-bottom-16 f-background radius12"
				v-for="(items,index) in noList" :key="index">
				<view class="back poa f-background width-height100"></view>
				<view class="address-item font-weight-600 color3 size-30">
					<view class="name">{{items.communityName || '-'}}</view>
					<view class="margin-bottom-12">
						<text v-if="items.building">{{items.building}}栋</text>
						<text v-if="items.unit">{{items.unit}}单元</text>
						<text v-if="items.number">{{items.number}}号</text>
						<text v-if="items.addressInfo">{{items.addressInfo}}</text>
					</view>
					<view class="color-9e font-weight-400 size-26">{{items.consignee}}{{sexData[items.sex]}}
						{{items.telephone}}
					</view>
				</view>
				<!-- <image class="add-icon poa" src="@/static/icons/bj.png" mode=""></image> -->
			</view>
		</view>
		<view class="f5-background inset-bottom"></view>
		<view class="operate f5-background poflb width100">
			<u-button type="primary" :plain="true"
				:customStyle="{width: '702rpx',height: '76rpx',borderRadius: '100rpx'}" :color="settings.color"
				@click="onJumpPage('address')">
				<view class="dis">
					<image class="adds-icon" src="@/static/icons/jiaxi.png" mode=""></image>
					<text class="color font-weight-600 size-28">添加</text>
				</view>
			</u-button>
			<view class="f5-background inset-bottom"></view>
		</view>
		<!-- </BodyMescroll> -->
	</view>
</template>

<script>
	const url = {
		address: "/packagePerson/address/add-editor"
	}
	import Default from "@/components/default/default"
	import { sexData } from "@/utils/enumeration/index"
	import { GetAddressInfoList } from "@/api/index"
	// import BodyMescroll from "@/components/body-mescroll/body-mescroll"
	import { dataSize, settings } from "@/utils/public"
	export default {
		components: {
			Default
		},
		data() {
			return {
				loading: true,
				sexData, // 性别枚举
				list: [],
				noList: [],
				totalPage: 0,
				// endByPage: false, // 是否隐藏下拉列表
				settings,
				// params: {
				// 	size: dataSize,
				// 	current: 1
				// },
				optionsType: 0,
			}
		},
		onShow() {
			this.postGetAddressInfoList()
		},
		onLoad(options) {
			this.optionsType = options.type * 1
			console.log('options', options.type)
		},
		methods: {
			onJumpPage(name, id) {
				console.log(name, id)
				let urlData = url[name]
				if (id) urlData = `${urlData}?id=${id}`
				uni.navigateTo({
					url: urlData
				});
			},
			// 点击选择并返回上一页
			onOptionsType(id, item, items) {
				if (!this.optionsType || items == 1) return
				let pages = getCurrentPages(); //获取当前页面
				let beforePage = pages[pages.length - 2] //获取上一个页面的实例
				console.log('pages', item, )
				// return
				beforePage.$vm.postOrderDetailInfo(item.communityId) //调用上一页面方法
				beforePage.$vm.postGetAddressInfoById(id) //调用上一页面方法
				console.log('beforePage.$vm',beforePage.$vm.amount.bean)
				beforePage.$vm.onShipment()
				uni.navigateBack({})
			},
			async postGetAddressInfoList(page) {
				// const { params, list } = this
				// params.current = page || params.current;
				const id = uni.getStorageSync('village').id
				const { data, code } = await GetAddressInfoList({ communityId: this.optionsType ? id : 0 })
				if (code == "200") {
					this.list = data.availableAddress
					this.noList = data.notAvailableAddress || []
					// this.endByPage = true
					this.loading = false
					// this.onByPage(params.pageSize,data.total,true) // 隐藏下拉刷新和上拉加载的状态, 在联网获取数据成功后调用
				}
			}
		}
	}
</script>

<style lang="scss">
	.AddressList {
		padding: 16rpx 16rpx 138rpx;
		width: 100%;
		box-sizing: border-box;
		.delivery{
			width: 100%;
			height: 106rpx;
			color: #888888;
		}
		.address-item {
			padding: 26rpx 24rpx;
		}
		.back{
			left: 0;
			top: 0;
			z-index: 10;
			opacity: .5;
			
		}
		.name {
			margin-bottom: 14rpx;
		}

		.add-icon {
			width: 28rpx;
			height: 28rpx;
			top: 28rpx;
			right: 28rpx;
		}

		.operate {
			padding: 28rpx 0;
			z-index: 11;
			.adds-icon {
				width: 24rpx;
				height: 24rpx;
				margin-right: 8rpx;
			}
		}
	}
</style>